package com.evan.uyclub.GameBa;

import android.graphics.Color;
import android.os.Bundle;
import android.view.Window;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.LinearLayout;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import com.evan.uyclub.Other.VPNActivity;
import com.evan.uyclub.R;
import com.gyf.immersionbar.BarHide;
import com.gyf.immersionbar.ImmersionBar;
import com.just.agentweb.AgentWeb;
import com.just.agentweb.WebChromeClient;
import com.sdsmdg.tastytoast.TastyToast;

import butterknife.BindView;
import butterknife.ButterKnife;

public class GameWeb extends AppCompatActivity {

    @BindView(R.id.root)
    LinearLayout root;
    @BindView(R.id.toolbar)
    Toolbar toolbar;

    private AgentWeb mAgentWeb;
    private WebChromeClient mWebChromeClient = new WebChromeClient() {
        @Override
        public void onReceivedTitle(WebView view, String title) {
            super.onReceivedTitle(view, title);
            toolbar.setTitle(title);
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Window window = this.getWindow();
        window.setStatusBarColor(Color.BLACK);

        //vpn检测
        VPNActivity vpnActivity = new VPNActivity(this);

        setContentView(R.layout.activity_gameweb);
        ButterKnife.bind(this);

        //全屏
        ImmersionBar.with(this).hideBar(BarHide.FLAG_HIDE_BAR).fullScreen(true).init();


        toolbar.setTitle(getString(R.string.app_name));
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);
        toolbar.setNavigationOnClickListener(v -> finish());

        mAgentWeb = AgentWeb.with(this)
                .setAgentWebParent(root, new LinearLayout.LayoutParams(-1, -1))
                .useDefaultIndicator(Color.parseColor("#5187f4"))
                .setWebChromeClient(mWebChromeClient)
                .createAgentWeb()
                .ready()
                .go(getIntent().getStringExtra("网址"));
        mAgentWeb.getWebCreator().getWebView().setOverScrollMode(WebView.OVER_SCROLL_NEVER);
        mAgentWeb.getWebCreator().getWebView().getSettings().setUserAgentString(WebSettings.getDefaultUserAgent(GameWeb.this));
        TastyToast.makeText(GameWeb.this, "点击Play Game开玩", TastyToast.LENGTH_SHORT, TastyToast.SUCCESS).show();

    }

    @Override
    public void onBackPressed() {
        if (!mAgentWeb.back()) {
            finish();
        }
    }
}